<?php

namespace App\Admin\Forms;

use App\Helpers\ApiResponse;
use App\Models\Refund;
use App\Services\RefundService;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;

class RefundCheck extends Form implements LazyRenderable
{
    use LazyWidget;

    // API接口响应
    use ApiResponse;

    public function handle(array $input)
    {
        $refundId = $input['id'];
        $checkStatus = $input['state'];
        $rejectReason = $input['reject_reason'];
        RefundService::getInstance()->refundCheck($refundId, $checkStatus, $rejectReason);
        return $this->response()->success('成功')->refresh();
    }

    public function default()
    {
        return [
            // 展示上个页面传递过来的值
            'id' => $this->payload['id'] ?? '',
        ];
    }

    public function form()
    {
        $this->hidden('id');
        $this->radio('state', '审核')->options(Refund::checkMap())->default(Refund::STATE_PASSED);
        $this->text('reject_reason');
    }
}
